package com.summerlabs.nfc.ui

import android.content.Intent
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.summerlabs.nfc.databinding.ActivityNfcReadBinding
import com.summerlabs.nfc.utils.NfcUtils
import com.summerlabs.nfc.utils.WLog

class NfcReadActivity : AppCompatActivity() {
    private lateinit var binding: ActivityNfcReadBinding
    lateinit var nfcUtils: NfcUtils
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = ActivityNfcReadBinding.inflate(layoutInflater)
        setContentView(binding.root)
        nfcUtils = NfcUtils(this)
    }

    override fun onNewIntent(intent: Intent) {
        super.onNewIntent(intent)
        nfcUtils.readNFCId(intent)?.let { tagId ->
            binding.cardId.text = tagId
        }
        nfcUtils.readMessage(intent)?.let { tagMsg ->
            binding.cardMsg.text = tagMsg
        }

    }

    override fun onResume() {
        super.onResume()
        WLog.i("onResume")
        nfcUtils.enableForegroundDispatch()
    }

    override fun onPause() {
        super.onPause()
        WLog.i("onPause")
        nfcUtils.disableForegroundDispatch()
    }
}